/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Action;

import ActionForm.mobLisHojaRutaActionForm;
import BE.Cliente;
import BE.Ocurrencia;
import BL.ClienteBL;
import BL.OcurrenciaBL;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import java.util.*;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Maestria
 */
public class mobLisHojaRutaAction extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)


           throws java.lang.Exception {
      // TODO: implement add method

        mobLisHojaRutaActionForm objClienteForm = new mobLisHojaRutaActionForm(request);

        HttpSession session = request.getSession();

        Cliente objClienteBE = new Cliente(objClienteForm);

        ClienteBL objClienteBL = new ClienteBL();


        Ocurrencia objOcurrenciaBE = new Ocurrencia();
        OcurrenciaBL objOcurrenciaBL = new OcurrenciaBL();

        objOcurrenciaBE.setBoolClienteesta(true);
        objOcurrenciaBE.setCvDescripcion("");
        objOcurrenciaBE.setCvNombre("");

        List<Ocurrencia> arrOcurrenciaEsta = objOcurrenciaBL.buscarOcurrenciaMovilEsta(objOcurrenciaBE);
        List<Ocurrencia> arrOcurrenciaNoEsta = objOcurrenciaBL.buscarOcurrenciaMovilNoEsta(objOcurrenciaBE);
        request.setAttribute("arrOcurrenciaEsta",arrOcurrenciaEsta);
        request.setAttribute("arrOcurrenciaNoEsta",arrOcurrenciaNoEsta);

        int intIdUsuario = (Integer) session.getAttribute("uid");
      
        List<Cliente> arrClientes = objClienteBL.buscarClientesHojaRuta(objClienteBE,intIdUsuario);
        //List<Cliente> arrClientes = objClienteBL.buscarCliente(objClienteBE);

        if((arrClientes!=null)&&(arrClientes.size()>0))
        {
        request.setAttribute("arrClientes", arrClientes);
        return mapping.findForward("mostrarHojaRuta");

        }
        else
        {
            Date fecha= new Date();
            request.setAttribute("strMensaje", "Ya se visitaron a todos los clientes programados para el día de hoy");
            return mapping.findForward("mobMenuPrincipal");
        } }
}
